<!--资产添加-->
<template>
  <div style="margin-top: 60px;margin-left:330px;width: 300px;height: 500px;border: 0px solid red;" >
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
      <el-form-item label="任务名称" prop="taskName">
        <el-input v-model="ruleForm.taskName"></el-input>
      </el-form-item>


      <el-form-item label="组织机构" prop="relatedOrg">
        <el-select v-model="ruleForm.relatedOrg" placeholder="请选择资产所属组织">
          <el-option v-for="item in OrgList" :label="item.orgName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="参与的测试人员" prop="joinedTesters">
        <el-select v-model="ruleForm.joinedTesters" placeholder="请选择测试人员">
          <el-option v-for="item in tbIfAdminList" :label="item.username" :value="item.id"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="活动状态" prop="taskStatus">
        <el-select v-model="ruleForm.taskStatus" placeholder="请选择资产类别">
          <el-option label="未开始" value="未开始"></el-option>
          <el-option label="已开始" value="已开始"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>
<script>
export default {
  data() {
    return {
      category:null,
      ruleForm: {
        taskName: '',
        relatedOrg: '',
        joinedTesters: '',
        taskStatus:'',
      },
      tbIfAdminList: '',
      OrgList: '',
      rules: {
        taskName: [
          { required: true, message: '请输入资产编号', trigger: 'blur' }
        ],
        relatedOrg: [
          { required: true, message: '请输入资产型号', trigger: 'blur' }
        ],
        joinedTesters: [
          { required: true, message: '请输入标签', trigger: 'blur' }
        ],
        assetCategory: [
          { required: true, message: '请输入标签', trigger: 'change' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {

          axios.post('http://localhost:8181/tbTaskAttack/save',_this.ruleForm).then(function (resp) {
            if(resp.data.code == 0){
              _this.$alert(_this.ruleForm.taskName+'添加成功', '', {
                confirmButtonText: '确定',
                callback: action => {
                  // _this.$router.push('/searchTest3')
                }
              });
            }
          })
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
    const _this = this;

    // 获取所属组织数据
    axios.get('http://localhost:8181/tbAssertOrg/list').then(function (resp) {
      console.log(resp.data);  // 确保控制台中打印了正确的数据
      _this.OrgList = resp.data.data;
    });

    // 获取资产负责人数据
    axios.get('http://localhost:8181/tbIfadmin/list').then(function (resp) {
      _this.tbIfAdminList = resp.data.data;
    });
  }

}
</script>